package com.moore.mapper;

import org.apache.ibatis.annotations.*;

@Mapper
public interface LikeMapper {

    @Select("SELECT COUNT(*) > 0 FROM `like` WHERE community_id = #{communityId} AND candidate_id = #{candidateId}")
    boolean existsByCommunityIdAndCandidateId(@Param("communityId") Long communityId,@Param("candidateId") Long candidateId);

    @Select("SELECT COUNT(*) > 0 FROM `like` WHERE community_id = #{communityId} AND comment_id = #{commentId} AND candidate_id = #{candidateId}")
    boolean existsByCommunityIdAndCommentIdAndCandidateId(@Param("communityId") Long communityId, @Param("commentId") Long commentId, @Param("candidateId") Long candidateId);

    @Insert("INSERT INTO `like` (community_id, comment_id, candidate_id) VALUES (#{communityId}, #{commentId}, #{candidateId})")
    int insertComment(@Param("communityId") Long communityId, @Param("commentId") Long commentId, @Param("candidateId") Long candidateId);

    @Insert("INSERT INTO `like` (community_id, candidate_id) VALUES (#{communityId}, #{candidateId})")
    int insertCommunity(@Param("communityId") Long communityId, @Param("candidateId") Long candidateId);

    @Delete("DELETE FROM `like` WHERE community_id = #{communityId} AND comment_id = #{commentId} AND candidate_id = #{candidateId}")
    int deleteByCommunityIdAndCommentIdAndCandidateId(@Param("communityId") Long communityId, @Param("commentId") Long commentId, @Param("candidateId") Long candidateId);

    @Delete("DELETE FROM `like` WHERE community_id = #{communityId} AND candidate_id = #{candidateId}")
    int deleteByCommunityIdAndCandidateId(@Param("communityId") Long communityId, @Param("candidateId") Long candidateId);
}